<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>
        单据冲单
    </h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>
                                        出入库类别
                                    </label>
                                    <select id="inOutType" name="inOutType" class="form-control">
                                        <option value="1" selected="selected">入库</option>
                                        <option value="2">出库</option>
                                    </select>
                                </div>

                                <div class="form-group">
                                    <label>单据编号</label>
                                    <input type="text" id="odrCode" name="odrCode"
                                           class="form-control"
                                           placeholder="请输入单据编号">
                                </div>
                                <div class="form-group">
                                    <label>制单人</label>
                                    <input type="text" id="odrMakePerson" name="odrMakePerson"
                                           class="form-control"
                                           placeholder="请输入制单人">
                                </div>
                                <div class="form-group">
                                    <label>
                                        单据类型
                                    </label>
                                    <select id="odrType" name="odrType" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="1">采购入库</option>
                                        <option value="2">退料入库</option>
                                        <option value="6">调拨入库</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>
                                        红冲过滤
                                    </label>
                                    <select id="odaRedFlag" name="odaRedFlag" class="form-control">
                                        <option value="1" selected="selected">不显示红冲</option>
                                        <option value="2">只显示红冲</option>
                                        <option value="">全部</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>制单日期</label>
                                    <input type="text" class="form-control datepicker" id="startOdrDate"
                                           name="startOdrDate"
                                           readonly="readonly"/>
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" id="endOdrDate"
                                           name="endOdrDate"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">搜索</button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="row" id="toolbar">
                    <div class="form-inline">
                        <button shiro:hasPermission="matinv:matreverse:edit" type="button"
                                class="btn btn-danger"
                                id="btn-togetherRed">
                            批量红冲
                        </button>
                    </div>

                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div id="goToTop"
     th:style="|position:fixed; right:0px; bottom:10px; width:20px; height:75px; background-image: url(@{/img/gototop.gif}); cursor:pointer|"></div>
<div th:include="include :: footer"></div>

<script th:inline="javascript">

    /**加载表格*/
    var table;

    /** 单条红冲 */
    function redDetailSingle(odaId,odrType) {
        if(odrType == 5||odrType == 6){
            js.modal.warning("红冲失败！调拨只能批量红冲！");
            return
        }
        js.modal.confirm("确定要红冲该条明细吗？", function (result) {
            js.post({
                url: ctx + "material/order/redDetailSingle",
                data: {
                    odaId: odaId
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            })
        })
    }

    $(function () {

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "material/order/orderDetailInfo",
            pageSize: 300,
            columns: [
                {
                    field: "checked",
                    title: '全选',
                    checkbox: true,
                    formatter: function (value, row, index) {
                        if (row.odaRedFlag === 2) {
                            return {
                                disabled: true,
                            }
                        } else {
                            return {
                                disabled: false,
                            }
                        }
                    }
                },
                {title: '单据编号', field: 'odrCode'},
                {title: '物料描述', field: 'matNameDesc'},
                {title: '单据类型', field: 'odrType',visible: false},

                {title: '数量', field: 'odaNum'},
                {title: '理论重量', field: 'odaWeight'},
                {title: '跟踪号', field: 'odaTrackCode'},
                {title: '项目编号', field: 'odaProCode'},
                {title: '项目名称', field: 'odaProName'},
                {
                    title: '在库类型', field: 'odaInType',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '库存在库';
                        } else if (value === 2) {
                            return '项目在库';
                        }
                    }
                },
                {title: '回货日期', field: 'odaBackDate', width: '105'},
                {title: '特殊说明', field: 'odaSpec'},
                {title: '库位', field: 'odrWhiName', width: '70'},
                {title: '制单日期', field: 'odrMakeDate', width: '90'},
                {title: '制单人', field: 'odrMakePerson'},
                {
                    title: '操作', width: '80',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP("materialstock:edit") && (row.odaRedFlag === 1)) {
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="redDetailSingle(' + row.odaId + ','+row.odrType+')"> 红冲</a>');
                        }
                        return actions.join('');
                    }
                }
            ],
            rowStyle: function (row, index) {
                if (row.odaRedFlag === 2) {
                    return {css: {"color": "red"}}
                } else {
                    return {css: {"color": "black"}}
                }
            }
        });

        /** 表格搜索 */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

        /** 出入库类别改变 联动单据类型 */
        $("#inOutType").change(function () {
            if ($("#inOutType").val() == 1) {
                // 1出库
                $("#odrType").empty().append('<option value="1">采购入库</option>').append('<option value="2">退料入库</option>').append('<option value="6">调拨入库</option>');
            } else if ($("#inOutType").val() == 2) {
                // 2出库
                $("#odrType").empty().append('<option value="4">领料出库</option>').append('<option value="5">调拨出库</option>');
            }
        })

        /** 批量红冲 */
        $("#btn-togetherRed").click(function () {

            var rows = js.table.selectRows("bootstrap-table");

            // 如果没有选择，显示提示信息
            if (rows.length == 0) {
                js.modal.warning("请至少选择一条明细");
                return false;
            } else {
                var arr = js.table.selectColumns(table, "odaId");
                js.post({
                    url: ctx + "material/order/redDetailTogether",
                    contentType: "application/json",
                    data: JSON.stringify(arr),
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            js.modal.success(result.msg);
                            js.table.refresh(table);
                        } else {
                            js.modal.warning(result.msg);
                            js.table.refresh(table);
                        }
                        js.modal.closeLoading();

                    }
                })
            }
        });

    })

</script>

</body>
</html>